<template>
  <view class="content">
    <view style="padding: 10px;z-index: 100;">
          <uni-forms>
            <uni-forms-item label-width="80px" label="工厂名称" required>
              <uni-easyinput placeholder="请输入工厂全称" v-model="item.comName"/>
            </uni-forms-item>
            <uni-forms-item label-width="80px" label="类型">
              <uni-data-select
                  placeholder="请选择类型"
                  v-model="item.type"
                  :localdata="range">
              </uni-data-select>
            </uni-forms-item>

            <uni-forms-item label-width="80px" label="所在地区" >
              <uni-data-picker
                  :map="{text:'name',value:'id'}"
                  placeholder="请选择省市区"
                  :step-searh="true"
                  :localdata="areas"
                  v-model="item.area">
              </uni-data-picker>
            </uni-forms-item>

            <uni-forms-item label-width="80px" label="详细地址" >
              <uni-easyinput placeholder="请输入详细地址(非必填)" v-model="item.address"/>
            </uni-forms-item>
            <uni-forms-item label-width="80px" label="联系人" >
              <uni-easyinput placeholder="请输入联系人(非必填)" v-model="item.linkman"/>
            </uni-forms-item>
            <uni-forms-item label-width="80px" label="联系电话" >
              <uni-easyinput placeholder="请输入电话(非必填)" v-model="item.phone"/>
            </uni-forms-item>
          </uni-forms>
      <view style="width: 60%;margin: 0 auto;">
        <button type="primary" class="block bg-blue lg round" style="width: 100%;" @click="addCompany()">提交</button>
      </view>
    </view>
  </view>
</template>


<script>
import {areaList} from "@/api/system/area";
import {addComInfo} from "@/api/company/info.js";


export default {
  data() {
    return {
      item: {
        comName: '',
        area: '',
        type: 0,
        address: '',
        linkman: '',
        phone: '',
        userId: ''
      },
      areas: [],
      range: [
        {text: '国有企业', value: '1'},
        {text: '集体所有制', value: '2'},
        {text: '私营企业', value: '3'},
        {text: '股份制企业', value: '4'},
        {text: '联营企业', value: '5'},
        {text: '外商投资企业', value: '6'},
        {text: '股份合作企业', value: '7'}]
    }
  },
  created() {

  },
  mounted() {
    this.getAreaList()
  },
  methods: {
    /**
     *  获取省市区列表
     */
    getAreaList() {
      areaList({level: 1}).then(res => {
        this.areas = res.rows
      })
    },
    /**
     * 新增企业
     */
    addCompany() {
      this.item.userId = this.$store.getters.userId
      addComInfo({...this.item}).then(res => {
        if (res.code === 200) {
		  this.$store.dispatch('GetInfo').then(res=>{
			  this.$modal.loading("注册成功,即将前往系统...")
			  setTimeout(() => {
			    wx.switchTab({url: '/pages/index'})
			  }, 3000)
		  })
        } else {
          this.$modal.loading('服务器繁忙，请稍后再试...')
        }

      })
    },
  },
}
</script>

<style scoped lang="scss" scoped>
	page {
	  background-color: #fff;
	}
</style>